package com.mlnx.data.service.iml;

import com.mlnx.common.form.PageForm;
import com.mlnx.common.utils.MyLog;
import com.mlnx.data.dao.BpStore;
import com.mlnx.data.entity.BpInfo;
import com.mlnx.data.pojo.form.BpInfoForm;
import com.mlnx.data.pojo.vo.BpInfoVo;
import com.mlnx.data.service.BpDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zzb
 * @create 2019/10/23 14:25
 */
@Service
public class BpDataServiceImpl implements BpDataService {

    private MyLog log = MyLog.getLog(getClass());
    @Autowired
    private BpStore bpStore;

    @Override
    public void save(BpInfo bpInfo) {
        try {
            bpStore.save(bpInfo);
        } catch (Exception e) {
            log.error("收到重复数据{}",bpInfo.toString());
        }
    }

    @Override
    public List<BpInfo> getBps(Integer patientId, Long startTime, Long endTime) {
        return bpStore.getBps(patientId, startTime, endTime);
    }

    @Override
    public void updateBps(List<BpInfo> bpInfos) {
        for (BpInfo bpInfo : bpInfos) {
            bpStore.updateBp(bpInfo);
        }
    }

    @Override
    public void deleteBps(List<BpInfo> bpInfos) {
        for (BpInfo bpInfo : bpInfos) {
            bpStore.deleteBp(bpInfo);
        }
    }

    @Override
    public BpInfoVo getAllBps(PageForm pageForm,@Valid BpInfoForm bpInfoForm) {

        return  bpStore.getPageBps(pageForm,bpInfoForm);
    }

    @Override
    public void updateBp(BpInfo bpInfo) {
        bpStore.updateBp(bpInfo);
    }
}
